This topic provides numerous useful examples of the various ways you can use reference methods in your device template files to perform conversions with constant values and/or reference data group element values. A sample device template file using each example is available upon request; it can be loaded to a DDS and used to test your reference methods. It is called ReferenceTester.dtf. In this topic, methods are described that compute a value from or provide a value for a single bit position. To make multi-bit changes, see Bit Mask.
See the following subsections for details:
For information about example data group elements and values used below, see Example Values.
The following example references the data group element raw61 and requests the binary value of the bit in bit position 2. The result of BitPosA is 1 because the binary value of the bit in bit position 2 of the decimal value 61 (binary 0011 1101) is 1. (Bit position enumeration starts with 0, the least significant bit position.)
|
<BitPosA desc="Bit Position Method A" readOnly="true" type="ui2" ref="raw61" bPos="2"/> |
Useful attributes to know are ref and bPos.
The following example references the data group element raw61 and references the operation opBitPos to request the binary value of the bit in bit position 2. The result of BitPosB is 1 because the binary value of the bit in bit position 2 of the decimal value 61 (binary 0011 1101) is 1. (Bit position enumeration starts with 0, the least significant bit position.)
|
<BitPosB desc="Bit Position Method B" readOnly="true" type="ui2" isRef="1"> <ref prec="0" refOp="opAssignId" deid="raw61"/> <ref prec="1" refOp="opBitPos" value="2"/> </BitPosB> |
Useful attributes to know are isRef, refOp, value, and deid. A useful element to know is ref.
The following example uses two child elements to perform a bit stuff on the parent element. The first child element references the operation opAssign to assign the initial decimal value "0" to BitStuff. The second child element references the opBitStuff operation and inserts the Boolean value "1" from the data group element raw1 into bit position "1" of BitStuff. The final value for BitStuff is a decimal value of 2 (binary 0000 0010) because a 1 is inserted into bit position 1; this signifies a decimal value of 2. (Bit position enumeration starts with 0, the least significant bit position.)
|
<BitStuff desc="Bit Stuff ID" readOnly="true" type="ui2" isRef="1"> <ref prec="0" refOp="opAssign" value="0"/> <ref prec="1" refOp="opBitStuff" deid="raw1" bPosDest="1"/> </BitStuff> |
Useful attributes to know are isRef, refOp, value, deid, and bPosDest. A useful element to know is ref.